package com.yuneec.droneservice.command;

import com.yuneec.droneservice.request.IResponse;
import com.yuneec.droneservice.utils.ByteUtils;

import java.util.Arrays;

/**
 * Created by gjw on 2017/3/27.
 */

public class GetChannelFormula extends BaseCommand {

    public GetChannelFormula(int index) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_GET_CH_CURVE);
        data = new byte[]{(byte) index};
    }

    @Override
    public IResponse toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        IResponse<int[]> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            int[] formula = new int[17];
            for (int i = 0; i < 17; i++) {
                formula[i] = ByteUtils.byteArrayToShort(Arrays.copyOfRange(data, off + 2 + 2 * i, off + 2 + 2 * i + 2), IS_BIGENDIAN);
            }
            response.setParam(formula);
        }
        return response;
    }

}
